package com.icss.day03;

import java.io.IOException;

public class Test20 {
    public static void main(String[] args) {
        // 定义方法 两个int的加法

        int r = 0;
        try {
            r = add(1, 2);
            System.out.println(r);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } finally {
            System.out.println("finally 无论是否有异常都会执行的代码");
        }

        try {
            r = add(0x7FFFFFFF, 1);
            System.out.println(r);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } finally {
            System.out.println("finally 无论是否有异常都会执行的代码");
        }
        System.out.println("---------------");

    }

    public static int add(int i, int j) throws IOException {

        if (Integer.MAX_VALUE - j < i) {
            throw new IOException("超过最大值了");
        }

        return i + j;
    }
}
